package com.mvc.web.common.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class StringUtils {
	 public static boolean isEmpty(String strIn) {
	        return strIn == null || "".equals(strIn) || "".equals(strIn.trim());
	    }
	 
	 public static boolean isNotEmpty(String strIn) {
		 return !isEmpty(strIn);
	 }

	public static int parseInt(String str, int i) {
		if(str == "" || str ==null || "".equals(str.trim())){
			return i;
		}else{
			return Integer.parseInt(str);
		}
	}
	
	public static int getAgeFromBirthday(String str){
		if(isEmpty(str)){
			return 0;
		}
		String[] strs = str.split("-");
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		String nowTime = df.format(new Date());
		String[] nows   = nowTime.split("-");
		
		Integer age= Integer.parseInt(nows[0]) - Integer.parseInt(strs[0]);
		//判断月份是否减一
		if(Integer.parseInt(nows[1]) - Integer.parseInt(strs[1])>0){
			age = age -1;
		}
		return age;
		
	}
}
